package com.demo.logistics.stockControl.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.demo.logistics.R;
import com.demo.logistics.stockControl.INewProductView;
import com.demo.logistics.stockControl.presenter.StockPresenter;

public class NewProductView extends StockView implements INewProductView{
	private StockPresenter _present;
	private EditText edProdName;
	private EditText edBrand;
	private EditText edPrice;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.product_maint_view);
		super.bindLogoEvent();
		edProdName = (EditText)findViewById(R.id.txt_prod_name);
		edBrand = (EditText)findViewById(R.id.txt_prod_brand);
		edPrice = (EditText)findViewById(R.id.txt_prod_price);
		_present = new StockPresenter(this);
		bindSubmitButtonEvent();
		bindSubmitDoneButtonEvent();
	}

	@Override
	public void bindSubmitButtonEvent() {
		Button btn = (Button)findViewById(R.id.btn_submit);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				boolean valid = _present.handleProductSubmitBtn(edProdName.getText().toString(), edBrand.getText().toString(), edPrice.getText().toString());
				if(valid){
					startActivity(new Intent(getApplicationContext(), NewProductView.class));
				}
				else{
					displayErrorMessage(_present.getErrorMsg());
				}
			}
		});
	}

	@Override
	public void bindSubmitDoneButtonEvent() {
		Button btn = (Button)findViewById(R.id.btn_submit_done);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				boolean valid = _present.handleProductSubmitBtn(edProdName.getText().toString(), edBrand.getText().toString(), edPrice.getText().toString());
				if(valid){
					startActivity(new Intent(getApplicationContext(), ProductListView.class));
				}
				else{
					displayErrorMessage(_present.getErrorMsg());
				}
			}
		});
		
	}
	
}
